﻿var curstate = 0; //当前类别选项
var datalist = {};
var rate=0;
var td_first=0;
var td_second=0;
var td_third=0;
var td_four=0;
var MOBILE=true;
$(function(){
	TEAM=getUrlParam("team");
	getRate();
	// getBtn();
    getOrder();//加载订单
	CustomersLoad();//客户昵称
	SuppliersLoad();//供应商列表
	SalesLoad();//业务列表
	PurchasesLoad();//采购列表
	$(UserRoles).show();
	if(APP){
		$("#order_term_btn").remove();
	}else{
		$("#order_term_btn").show();
	}
	chromatableTwo();
 	//导航栏的选中
     $('.wrapper').navbarscroll();
    $("#categories li").eq(0).addClass("cur").siblings().removeClass("cur");
    //采购订单 输入买$ 反推买￥ 退点
    $("#_priceUSD").on("keyup",function(){
    	var _isFancy=$("#_isFancy").val();
    	var usd_val=Number($("#_priceUSD").val());//买$
	   	var _rate=Number($("#_purchaseExchange").val());//汇率
	   	//买￥
    	var rmb_val=formatRMBPrice(usd_val*_rate);
    	$("#_purchaseRMB").val(rmb_val);
    	if(_isFancy==0){//白钻
	    	//退点
	    	var _rap=Number($("#_rapnet").val());
	    	var _wei=Number($("#_weight").val());
	    	var _dis=((100*usd_val)/(_wei*_rap))-100;
	    	$("#_discountReturn").val(_dis.toFixed(2));
    	}
    });
    //采购订单 输入退点 反推买￥ 买$
    $("#_discountReturn").on("keyup",function(){
    	var _isFancy=$("#_isFancy").val();
    	if(_isFancy==0){//白钻
	    	//退点
	    	var _dis=Number($("#_discountReturn").val());
	    	var _rap=Number($("#_rapnet").val());
	    	var _wei=Number($("#_weight").val());
	    	var usd_val=_rap*(100+_dis)/100*_wei;
	    	$("#_priceUSD").val(formatUSDPrice(usd_val));
		   	var _rate=Number($("#_purchaseExchange").val());//汇率
		   	//买￥
	    	var rmb_val=formatRMBPrice(usd_val*_rate);
	    	$("#_purchaseRMB").val(rmb_val);
    	}
    });
    //采购订单 输入汇率 改变买价
    $("#_purchaseExchange").on("keyup",function(){
    	var _rate=Number($("#_purchaseExchange").val());//汇率
    	var usd_val=Number($("#_priceUSD").val());//买$
    	var rmb_val=formatRMBPrice(usd_val*_rate);
	    $("#_purchaseRMB").val(rmb_val);
    });
	//排序
    $("#product_table th").on("click", function () {
        var sort = $(this).children("i");
        if (sort.length > 0) {
            var iSort = $(this).children("i");
            var sortName = iSort.attr("data-sort");
            var sortDirect = iSort.attr("data-sort-direct");
            if (!sortDirect) {
                sortDirect = "asc";
            }
            else if (sortDirect == "asc") {
                sortDirect = "desc";
            }
            else if (sortDirect == "desc") {
                sortDirect = "";
            }

            iSort.attr("data-sort-direct", sortDirect);
            iSort.removeClass("sort_asc").removeClass("sort_desc").removeClass("sort_normal");
            iSort.addClass("sort_" + sortDirect);

            $("th i").not(iSort).removeClass("sort_asc").removeClass("sort_desc").removeClass("sort_normal");
            $("th i").not(iSort).removeAttr("data-sort-direct");

            $("th i[data-sort='" + sortName + "']").addClass("sort_" + sortDirect).attr("data-sort-direct", sortDirect);
            getOrder();
        }
    });
  	//跳到证书
    $("#stock_body").on("click","a.cert_link_btn",function(){
    	var link_url=$(this).attr("data-href");
    	if(APP){
    		var appJson={};
   			appJson.title=_("证书");
   			appJson.url=app_url+link_url;
   			YiYi_APP.showNewPage(JSON.stringify(appJson));
    	}else{
    		location.href=link_url;
    	}
    });
    //点击详情关闭
    $("#product_table").on("click", ".stock_detail", function () {
        //$(this).hide();
    });
     //全选
    $("#product_table_fixed").on("click","#th_check_all",function(){
    	var $this=$(this).children().children("span");
		$this.toggleClass("selected")
		if($this.hasClass("selected")){
			$("tbody .check_list_box").children("span").addClass("selected");
			$("tbody tr.data_tr").addClass('tr_select_color');
			var td_total_num = $("tbody tr.data_tr").length
            $(".check_num").html(td_total_num);//全选的条数
            $(".check_first").html(formatRMBPrice(td_first));//
            $(".check_second").html(formatRMBPrice(td_second));
            $(".check_third").html(formatRMBPrice(td_third));
            $(".check_four").html(formatRMBPrice(td_four));
		}else{
			$("tbody .check_list_box").children("span").removeClass("selected");
			$("tbody tr.data_tr").removeClass('tr_select_color');
			clearAll();
			clear_total_stat();
		}
		datalist = {};
        for (var i = 0; i < $("tbody .check_list_box span.selected").length ; i++) {  //得到所有选中的行
            var _key = $("tbody .check_list_box span.selected").eq(i).attr("data");   //得到当前选中的行
            datalist[_key] = _key;
        }
        var lengths = 0;  //主要用来做首行判断
        var tempdata = true; //是否只有一种类别
        var first = 0;     //第一种类别记录
        for (var d in datalist) {
            if (lengths == 0) //记录第一次类别
                first = datalist[d];
            else {
                if (datalist[d] != first) //记录当前类别与首次不同
                {
                    tempdata = false;
                    break;
                }
            }
            lengths++; //记录增加1
        }
        if (tempdata) //全部类别一样
        {
            if (first != 0)  //并且记录到类别（选中了一个或以上）
                eval("check_checkbutton(" + first + ")");
            else if (curstate != 0)    //不是全选择（指待采购  待到货  待出货  已出货  已作废） order.cshtml里面有调用这个参数做类别记录
                eval("check_checkbutton(" + curstate + ")");  //调用对应的，主要用于取消全选时去掉对应的高亮按钮
            else //全部类别（不做处理先）
            { }
        } else {
            clearAll();
        }
        chromatableTwo();
    });
    //点击行展开详情
    $("#product_table").on("click", "tr.data_tr td", function (event) {
        var td_input = $(this).index();
        var len=$(this).parent("tr").children("td").length;
        if (td_input == 0||td_input == 1 || td_input==len-1) {
            //勾选框不展开详情
        } else {
            $(this).parent("tr").next(".stock_detail").slideToggle(0);
        }
    });
    
    
    $("#product_table").on("click",".ImageIcon",function(){
    	var params = {};
    	params.InventoryID = $(this).parent().attr("data-value");
    	params.OrderID = $(this).parent().attr("data-id");
    	params.HasImage = 1
    	getImages(params);
    });
    //点击视频icon 
	$("#product_table").on("click",".VideoIcon",function(){
    	var params = {};
    	params.InventoryID = $(this).parent().attr("data-value");
    	params.OrderID = $(this).parent().attr("data-id");
    	params.HasVideo = 1
    	getImages(params);
    });

    //选中
	var tt = 0;
	var count_first = 0;
	var count_second = 0;
	var count_third = 0;
	var count_four = 0;
	function toDecimal(x) {
	    var f = parseFloat(x);
	    if (isNaN(f)) {
	        return;
	    }
	    f = Math.round(x * 100) / 100;
	    return f;
	}
	 //选中
//	$("#product_table").on("click",".check_list_td",function(){
//		$(this).prev().children().find("span").toggleClass("selected");
//		$(this).parent("tr").toggleClass("tr_select_color");
//	});
    $("#product_table").on("click", ".check_rel", function () {
		//debugger
      	var me=$(this).parent("tr");
		s1 = $(this).children().find("span").attr('data'); //如果当前行选中，则取到对应类别
		 var c_num = Number($(".check_num").eq(0).text());
	    var first = formatRMBPrice($(this).attr("data-first"));
	    var total_first = formatRMBPrice($(".check_first").eq(0).text());

	    var second = formatUSDPrice($(this).attr("data-second"));
	    var total_second = formatUSDPrice($(".check_second").eq(0).text());

	    var third = formatRMBPrice($(this).attr("data-third"));
	    var total_third = formatRMBPrice($(".check_third").eq(0).text());

	    var four = formatUSDPrice($(this).attr("data-four"));
	    var total_four= formatUSDPrice($(".check_four").eq(0).text());
	    if (me.hasClass('tr_select_color')) {
	    	$(this).children().find("span").removeClass("selected");
	  		me.removeClass("tr_select_color");
	  		if (curstate == 0) {  //只有在全部状态下才执行，单一状态无需执行
	            if (s1 && datalist[s1])
	                datalist[s1] = datalist[s1] - 1;  //对应状态减少一次记录
	            if (datalist[s1] == 0)
	                delete datalist[s1];  //删除状态记录
	        }
			if(curstate == 1){ //代采购状态
                if (datalist[s1])
                    datalist[s1] = datalist[s1] + 1;  //对应状态增加一次记录
                else  //未记录这个状态则直接=1
                {
                    datalist[s1] = 1;
                }
			}

	        //add
	        tt = c_num - 1;
	        count_first = total_first - first;
	        count_second = (total_second - second);
	        count_third = (total_third - third);
	        count_four = (total_four - four);
	        //

	        if (curstate == 8 || curstate == 3) { //8正常订单。3待出货
	            var cdata = $(me).find("input").data('cidShipno')

	            if (cidAndShipNo.hasOwnProperty(cdata)) {  //如果有这个元素
	                if (cidAndShipNo[cdata]==1)  //如果元素为1个，取消则删除元素
	                    delete cidAndShipNo[cdata];
	                else
	                    cidAndShipNo[cdata] = (parseInt(cidAndShipNo[cdata]) - 1); //取消一次删除一个
	            }
	            _showShip = calcCountByDisc(cidAndShipNo) < 2;
	        }
        //
	    } else {
	    	if (curstate == 8 || curstate == 3) {
            var cdata = $(me).find("input").data('cidShipno')
            if (!cidAndShipNo.hasOwnProperty(cdata)) {
                cidAndShipNo[cdata] = 1;
            }
            else
                cidAndShipNo[cdata] = (parseInt(cidAndShipNo[cdata]) + 1); // 选中则添加一次记录
	            _showShip = calcCountByDisc(cidAndShipNo) < 2;
	        }

	        me.addClass('tr_select_color');
	        $(this).children().find("span").addClass("selected");
	        var s1=$(this).children().find("span").attr('data'); //如果当前行选中，则取到对应类别
	        if (datalist[s1])
	            datalist[s1] = datalist[s1] + 1;  //对应状态增加一次记录
	        else  //未记录这个状态则直接=1
	        {
	            datalist[s1] = 1;
	        }
	        //add
	        tt = c_num + 1;
	        count_first = total_first + first;
	        count_second = (total_second + second);
	        count_third = (total_third + third);
	        count_four = (total_four + four);
	    }
	   //add赋值
	    $(".check_num").text(tt);
	    $(".check_first").text(formatRMBPrice(count_first));
	    $(".check_second").text(formatUSDPrice(count_second));
	    $(".check_third").text(formatRMBPrice(count_third));
	    $(".check_four").text(formatUSDPrice(count_four));
	    //
	    var length = 0;
	    var method_num;
	    for (var s in datalist) {  // 分析类别统计记录
	        length++;         // 统计类别记录
	        method_num = s;  //记录类别对应的状态值
	    }
	    //买价  管理员可以修改已付未付的买价   其他只能修改未付的买价
	    var priceStatusSame;
	    var priceStatusVal=$("#product_table tr.tr_select_color");
	    if(priceStatusVal.length>0){
	    		$(".PurchaseExchangerate").css("background-color", primary_color);
	        	$(".PurchaseExchangerate").attr("disabled", false);
	    	//付款状态
			if(origin_roleID==1){//管理员时，已付未付均可修改买价
				$(".PurchasePrice").css("background-color", primary_color);
	        	$(".PurchasePrice").attr("disabled", false);
			}else{
				for(var i = 0; i < priceStatusVal.length; i++) {
					if(priceStatusVal.eq(i).attr("data-priceStatus")==0){
						priceStatusSame=true;
					}else{
						priceStatusSame=false;
					}
				}
				if(priceStatusSame==true){
					$(".PurchasePrice").css("background-color", primary_color);
	        		$(".PurchasePrice").attr("disabled", false);
				}else{
					$(".PurchasePrice").attr("disabled", true);
					$(".PurchasePrice").css("background-color", "#a1a1a1");
				}
			}
	    }else{
	    	$(".PurchasePrice,.PurchaseExchangerate").attr("disabled", true);
	    	$(".PurchasePrice,.PurchaseExchangerate").css("background-color", "#a1a1a1");
	    }
	    if (length == 1) {  //只有一种类别时，则调用对应的高亮按钮方法
	        eval("check_checkbutton(" + method_num + ")");
	    }
	    else //有多种类别时，取消高亮按钮
	    {
	    	clearAll();
	        //取消
	        if (length == 2 && datalist.hasOwnProperty(3) && datalist.hasOwnProperty(4)) { //只有2两种类别时，并且是待出3与已出4
	            eval("check_checkbutton(34)");
	        }
	    }
	    checkAllChecked();//是否全选
	    btnDelOrder();//回库删除按钮的高亮
     });

    //筛选
    $("#order_term_btn").on("click", function () {
//      $("#common_header").hide();
//      $("#order_term_box").show();
		var link_url="/Team/OrderFilter?type=1";
		if(APP){
			var appJson={};
   			appJson.title=_("订单筛选");
   			appJson.url=app_url+link_url;
   			YiYi_APP.showNewPage(JSON.stringify(appJson));
		}else{
			location.href=link_url;
		}
   });
    $(".order-status span").on("click", function () {//订单状态选中
        $(this).addClass("active").siblings().removeClass("active");
    });


    //点击收款事件
	$("#AddBill").click(function () {
        $("#_chargingAmount").val('');
		var _Balance = 0;
		var _USDBalance = 0;
		var _selected=$("#stock_body .check_list_box span.selected");
	    //用户数组start
	    selnamelist = {};//用户数组
	    pstalist = {};
        var rmbMoney=0;
        var usdMoney=0;
	    for (var i = 0; i < _selected.length ; i++) {//得到所有选中的行
	        var _skey = _selected.eq(i).parent().attr("lang");//得到当前选中的行的用户

	        var pays = _selected.eq(i).parent().attr("data-PaymentStatus");//得到收款状态值


            // var tempRmbMoney = Number(_selected.eq(i).parent().parent().parent().parent().find('.td_firstRMB').attr("title"));

            var tempRmbMoney = _selected.eq(i).parent().parent().attr("data-first");//得到收款状态值

            var tempUsdMoney = Number(_selected.eq(i).parent().parent().attr("data-second"));

            rmbMoney=addNum(rmbMoney,tempRmbMoney)
            usdMoney=addNum(usdMoney,tempUsdMoney);
            console.log("999")
            console.log(rmbMoney)

	        var orderstatuss =_selected.eq(i).attr("data");//得到订单状态值
	        selnamelist[_skey] = _skey;//用户数组
	        pstalist[pays] = pays;//支付数组
	        _Balance = Number(_selected.eq(i).parent().attr("data-Balance"));
	        _USDBalance = Number(_selected.eq(i).parent().attr("data-USDBalance"));
	    }
	    var sleng = 0;//主要用来做首行判断
	    var samename = true;//是否是同一用户
	    var sfirst = 0;//第一个用户记录
	    for (var ss in selnamelist) {
	        if (sleng == 0)//用户记录
	            sfirst = selnamelist[ss];
	        else {
	            if (selnamelist[ss] != sfirst) {//当前用户与首次不同
	                samename = false;
	                break;
	            }
	        }
	        sleng++;
	    }
	    var pleng = 0;//主要用来做首行判断
	    var psta = true;//是否是未收状态
	    for (var pp in pstalist) {
	        if (pstalist[pp] != 0) {//当前用户与首次不同
	            psta = false;
	            break;
	        }
	        pleng++;
	    }

	    if (samename) {
	        if (psta) {
	            //通过
	            $("#_payCustID").html(sfirst);//CustomerID 12-14
	            PayOrders_Js(orderstatuss,_Balance,_USDBalance,rmbMoney,usdMoney);//收款
	            //PayOrders(sfirst);
	        } else {
	           	if (orderstatuss == 7) {
	                PayOrders_Js(orderstatuss,_Balance,_USDBalance,rmbMoney,usdMoney);//收款
	            } else {
	                myApp.alert(_("【收款】选择不当！请选择“未收”订单"));
	            }
	        }
	    } else {
	        //未通过-不同一客户
	        if (orderstatuss == 7) {
	            PayOrders_Js(orderstatuss,_Balance,_USDBalance,rmbMoney,usdMoney);//收款
	        } else {
	            myApp.alert("【收款】"+_("选择不当！请选择“同一客户”的订单"));
	        }
	    }
	    //用户数组end
	});

});

//精准相加
function addNum(num1,num2){
    var r1,r2,m,n;
    try{r1=num1.toString().split(".")[1].length}catch(e){r1=0}
    try{r2=num2.toString().split(".")[1].length}catch(e){r2=0}
    m = Math.pow(10,Math.max(r1,r2));
    n = (r1>=r2)?r1:r2;
    return ((num1*m + num2*m)/m).toFixed(n);
}

 // 获取图片地址
function getImages(params){
	myApp.showIndicator();//显示加载中
	if(TEAM==0){
		var imagesUrl="/Customer/GetImgInfo";//客户端裸钻图片
	}else{
		var imagesUrl="/Team/GetImgInfo";//团队端裸钻图片
	}
    $.ajax({
        url: imagesUrl,//提交地址
        type: "POST",//提交方式
        data: JSON.stringify(params),
        contentType: "application/json; charset=utf-8",
        success: function (result) {
            var _result = eval('(' + result + ')');//eval()解析单个json对象
            if (_result.msgcode == true) {
            	myApp.hideIndicator();//隐藏加载中
            	if(params.HasImage==1){
            		var data=_result.msginfo;
					imgs = data.split(",");
					imgArray=[];
			        for (var i=0; i< imgs.length;i++) {
			            if (imgs[i].length > 10) {
			        		var big = imgs[i].replace('800x800', '1920x1920');
			        		imgArray.push(big)
			            }else{
			            	var img_null='/images/no_img.jpg';
			            	imgArray.push(img_null)
			            }
			        }
					//   @*主题色start*@
	                $(document.createElement("script")).attr("src","/Js/ThemesColor.js").appendTo("html");
					//  @*主题色end*@
					 //放大图片
					var myPhotoBrowserStandalone = myApp.photoBrowser({
					    photos : imgArray,
					    backLinkText: _('返回'),
					    ofText:"/",
					});
					if(APP){
						var ProductImg={};
						ProductImg['images']=imgArray;
						ProductImg['index']=0;
						YiYi_APP.showImages(JSON.stringify(ProductImg));
					}else{	
						myPhotoBrowserStandalone.open();
				    }	
            	}else if(params.HasVideo==1){
            		var firstImg = _result.msginfo.split(',')[0]; 
					if(APP){
						var ProductVideo={};
						ProductVideo.url = firstImg;
						YiYi_APP.showVideo(JSON.stringify(ProductVideo));
					}else{
						myApp.popup('.popup-services');
	            		var videoHtml=[];
						videoHtml.push(
							'<video src="'+firstImg+'" controls="controls"></video>'
						);
						$(".popup-services #PhotoSwipeTarget").html(videoHtml.join(''));
					}
            	}
            } else {
                myApp.alert(_result.msginfo);
            }
            myApp.hideIndicator();//隐藏加载中
        },
        error: function(XMLHttpRequest, textStatus, errorThrown){
			myApp.alert("网络超时，请重试");
			myApp.hideIndicator();//隐藏加载中
		}
    });
}
//判断是否全选
function checkAllChecked() {
    if ($("tbody .check_list_box span").length != $("tbody .check_list_box span.selected").length) {
        $("#th_check_all").find("span").removeClass("selected");
    }else {
        $("#th_check_all").find("span").addClass("selected");
    }
}
 //顶部二级按钮固定
function chromatableTwo() {
    var loadingStatus = 1;
    var _top = $(".orderBar").offset().top;
    var _height = $(".orderBar").height();
    var table_head = $("#product_table_fixed").height();

    if(APP){
    	$("#common_header").hide();
    	if($(".subnavbar").length>0){
    		var h=_height-table_head;
    	}else{
    		var h=0;
    	}
    	$("#app_no_header").css("padding-top",h);
    	$("#term_app_btn").hide();
    }else{
    	if($(".subnavbar").length>0){
    		if($(".subnavbar table").length>0){
    			var h=_height+_top-table_head;
    		}else{
    			var h=_height+_top;
    		}
    	}else{
    		var h=_top;
    	}
    	$("#app_no_header").css("padding-top",h);
    	$(".navbar").css("top","0px");
    	$("#common_header").show();
    	$("#term_app_btn").show();
    }
}
//清空统计
function clear_total_stat() {
    tt = 0;
    count_first = 0;
    count_second = 0;
    count_third = 0
    count_four = 0;
    $(".check_num").html(tt);
    $(".check_first").html(count_first);
    $(".check_second").html(count_second);
    $(".check_third").html(count_third);
    $(".check_four").html(count_four);
}
//去掉数组里的空值
Array.prototype.clean = function(deleteValue) {
  for (var i = 0; i < this.length; i++) {
    if (this[i] == deleteValue) {
      this.splice(i, 1);//返回指定的元素
      i--;
    }
  }
  return this;
}

// function  getBtn(){
// 	var transfer=ShowColumn("transfer")
// 	if(transfer == 1){
// 		$(".check_list").html('<li class=""><button class="search_btn_b ModifyPurchaseUserID" onclick=\'ModifyPurchaseUserID_Js()\' disabled="disabled">选采购</li>')
// 	}
// }
//获取订单
function getOrder() {
	myApp.showIndicator();//显示加载中
	if(PARAMS==null){
		var p={};
		p.OrderStatus="8";
		p.PageIndex="1";
		p.PageSize="200";
	 	// if (RoleID == 3 || RoleID == 6) {
	      //   p.SalesUserID = UserID;
	    // }
	    //采购员4
	    // if (RoleID == 4) {
	    //     p.PurchaseUserID = UserID;
	    // }

	}else{
		var p = PARAMS.orderParams;//获取参数
		//原货号
 		if(p.OriginSN!=undefined && p.OriginSN!=""){
     		var OriginSNValArray=p.OriginSN.split(" ");
			OriginSNValArray.clean("");
			p.OriginSN=OriginSNValArray;
		}
 		//证书号
 		if(p.CertNo!=undefined && p.CertNo!=""){
 			if(typeof p.CertNo!="string"){
                p.CertNo=p.CertNo.join('');
			}
			var CertNoValArray=p.CertNo.split(" ");
			CertNoValArray.clean("");
			p.CertNo=CertNoValArray;
		}
	}
	if(p.OrderStatus==1){  //代采购状态
        curstate=p.OrderStatu;
	}

   $("#choose_orderstatus").text(UserOrderStatusFormat(p.OrderStatus));
    //获取排序
    var sort = $("th i[data-sort-direct]");
    if (sort.length > 0 && sort.attr("data-sort-direct")) {
        p.SortColumn = sort.attr("data-sort");
        p.SortDirect = sort.attr("data-sort-direct");
    }

   	p.UserID=UserID;
    // var requestJson = data?data:JSON.stringify(p);
    var requestJson = JSON.stringify(p);
    $.ajax({
        url: "/Customer/GetOrders",
		data: requestJson,
        type: "post",
        contentType: "application/json; charset=utf-8",
        timeout: 60000, //超时时间：30秒
        success: function (result) {
			myApp.hideIndicator();//隐藏加载中
        	datalist = {}; //
           	bindingInventory(result);//绑定白钻
           	clearAll();
        	clear_total_stat();//清空统计
        	checkAllChecked();//是否全选
        	if(APP){
        		YiYi_APP.refreshOrderNumber();//重新统计状态数量
        	}

        },
        error: function(XMLHttpRequest, textStatus, errorThrown){
			myApp.hideIndicator();//隐藏加载中
			myApp.alert("网络超时，请重试");
		},
    });
}

//绑定数据
var order_price_btn=ShowColumn("order_price_btn");
var order_procurement_btn=ShowColumn("order_procurement_btn");
function bindingInventory(result) {
    var SalesExchangerate = ShowColumn("team_columns_SalesExchangerate")//销汇
    var Confirmdiscount = ShowColumn("team_columns_Confirmdiscount")//退点
    var ConfirmPrice = ShowColumn("team_columns_ConfirmPrice")//卖￥
    var ConfirmUSD = ShowColumn("team_columns_ConfirmUSD")//卖$
    var PaymentStatus = ShowColumn("team_columns_PaymentStatus")//收款
    var CustomerNickName = ShowColumn("team_columns_CustomerNickName")//客户
    var Balance = ShowColumn("team_columns_Balance")//余￥
    var USDBalance = ShowColumn("team_columns_USDBalance")//余$
    var SalesUserName = ShowColumn("team_columns_SalesUserName")//业务
    var PurchaseUserName = ShowColumn("team_columns_PurchaseUserName")//采购
    var PurchaseExchangerate = ShowColumn("team_columns_PurchaseExchangerate")//采汇
    var SupplierCode = ShowColumn("team_columns_SupplierCode")//供应商
    var ShipNo = ShowColumn("team_columns_ShipNo")//出货单号
    var DiscountReturn = ShowColumn("team_columns_DiscountReturn")//原退
    var PriceUSD = ShowColumn("team_columns_PriceUSD")//原$
    var PurchaseRMB = ShowColumn("team_columns_PurchaseRMB")//原￥
    var ReceiptStatus = ShowColumn("team_columns_ReceiptStatus")//付款
	var Detail=ShowColumn("supplier_detail")  //供应商详情

    var colspanVal=6;//6列固定项
    var $thead_html="<th style='width:8%' class='check_rel' id='th_check_all'>"+
        "<div class='check_list_box'>"+
        "<span class='checkbox' name='checkbox_all'></span>"+
        "</div>"+
        "</th>"+
        "<th style='width:10%'>"+_("重量")+"</th>"+
        "<th style='width:10%'>"+_("颜色")+"</th>"+
        "<th style='width:10%'>"+_("净度")+"</th>";
    if(Confirmdiscount==1 || RoleID ==1){
        colspanVal++;
        $thead_html+="<th style='width:10%'>"+_("退点")+"</th>";
    }
    if(ConfirmPrice==1 || ConfirmUSD==1 || RoleID == 1){
        colspanVal++;
        $thead_html+="<th class='purchase_sell' style='width:13%'>"+_("卖")+"</th>";
    }
    if(CustomerNickName==1 || RoleID == 1){
        colspanVal++;
        $thead_html+="<th class='customer' style='width:13%'>"+_("客户")+"</th>";
    }
    if(PaymentStatus==1 || RoleID == 1){
        colspanVal++;
        $thead_html+="<th class='buy' style='width:10%'>"+_("收款")+"</th>";
    }
    $thead_html+="<th style='width:15%'>"+_("状态")+"</th>";
    var resultDatas = JSON.parse(result);
    var row = resultDatas.msginfo.Data;
    var res='';
    var isfour=false;
    if(row){
        for (var i = 0; i < row.length; i++) {
            res = row[i].OrderStatus;
            if(res==4){
                isfour=true;
            }
        }
    }
    $thead_html += '<th style="width:15%">' + _("所在地") + '</th>';

    var $thead_html_hide="<th style='width:8%'></th>"+
        "<th style='width:10%'>"+_("重量")+"</th>"+
        "<th style='width:10%'>"+_("颜色")+"</th>"+
        "<th style='width:10%'>"+_("净度")+"</th>";
    if(Confirmdiscount==1 ||  RoleID ==1)
        $thead_html_hide+="<th style='width:10%'>"+_("退点")+"</th>";
    if(ConfirmPrice==1 || ConfirmUSD==1 || RoleID == 1)
        $thead_html_hide+="<th class='purchase_sell' style='width:13%'>"+_("卖")+"</th>";
    if(CustomerNickName==1 || RoleID == 1)
        $thead_html_hide+="<th class='customer' style='width:13%'>"+_("客户")+"</th>";
    if(PaymentStatus==1 || RoleID == 1)
        $thead_html_hide+="<th class='buy' style='width:10%'>"+_("收款")+"</th>";
    $thead_html_hide+="<th style='width:15%'>"+_("状态")+"</th>";
    $thead_html_hide += '<th style="width:15%">' + _("所在地") + '</th>';

    $("#product_table_fixed thead tr").html($thead_html);
    $("#product_table thead tr").html($thead_html_hide);
    td_first=0;
    td_second=0;
    td_third=0;
    td_four=0;
    var _result = JSON.parse(result);
    var tableTbody = $("#stock_body");
    //获取库存成功
    if (_result["msgcode"] == true) {

        if (_result.msginfo.Data.length == 0) {
            //无结果
            var tr = "";//单行
            var tds = "<td colspan='50' style='text-align:center;color:red'>" + _(_result["msginfo"]) + "</td>";// 多列合成一列并居中
            tr = "<tr>" + tds + "</tr>";//将多列加到一行
            tableTbody.html(tr);//加入到id为customer的table的tbody中
        } else {

            _result = _result.msginfo.Data;//object
            stock_json = _result;

            $("#easy_js").html('<script src="/Js/jquery.easyui.min.js"></script>');
            var trs = "";//多行数据

            for (var i = 0; i < _result.length; i++) {

                var tds = "";//多列
                var tr = "";//单行
                var tr_div = "";
                var data = _result[i];
                tds += "<td class='check_rel' lang='"+data.CustomerID+"' data-supplier='"+data.SupplierCode+"' data-first="+formatRMBPrice(data.ConfirmPrice)+" data-second="+
                    formatUSDPrice(data.ConfirmUSD)+" data-third="+formatRMBPrice(data.PurchaseRMB)+" data-four="+formatUSDPrice(data.PriceUSD)+">"+
                    "<div class='check_list_box' lang='"+data.CustomerID+"' data-PaymentStatus='"+data.PaymentStatus+"' data-Balance='"+data.Balance+
                    "' data-USDBalance='"+data.USDBalance+"' data-ReceiptStatus="+data.ReceiptStatus+">"+
                    "<span class='checkbox' name='checkbox' lang='" + data.OrderID + "' data='"+data.OrderStatus+"' data-Purchase='"+data.PurchaseUserName+"' data-Online='"+data.Online+"'></span></div>";
//              "<input type='checkbox' class='checkbox' value='check[i]' data='"+data.OrderStatus+"' name='checkbox'  lang='" + data.OrderID +"' /><div class='checkbox_fu'></div></td>";
                tds += "<td class='check_list_td'>" + data.Weight + "</td>";
                tds += "<td>" + ColorFormat(data.Color) + "</td>";
                tds += "<td>" + data.Clarity + "</td>";

                if(RoleID == 1 || RoleID == 2 || RoleID == 3 ||RoleID == 4|| RoleID == 5 || RoleID == 6 || RoleID == 7 ) {
                    if(data.Confirmdiscount - data.DiscountReturn <= 0 && data.OrderStatus != 5&& (Confirmdiscount==1 ||RoleID ==1 )) {
                        tds += "<td style='color:red;'>" + ConfirmdiscountFormat(data.Confirmdiscount) + "</td>";
                    }else{
                        if(Confirmdiscount==1 || RoleID ==1)
                            tds += "<td>" + ConfirmdiscountFormat(data.Confirmdiscount) + "</td>";
                    }
                }
                if($.cookie("CurrentSet") == 2){ //美金
                    if(ConfirmUSD==1 || RoleID == 1)
                        tds += "<td style='font-weight:bold' class=''>" + formatUSDPrice(data.ConfirmUSD) + "</td>";//四舍五入
                }else{ //全局0和人民币1显示人民币
                    if(ConfirmPrice==1 || RoleID == 1)
                        tds += "<td style='font-weight:bold' class=''>" + formatRMBPrice(data.ConfirmPrice) + "</td>";//四舍五入
                }
                if(CustomerNickName==1 || RoleID == 1)
                    tds += "<td class='customer'>" + partShowSubstring(data.CustomerNickName)  + "</td>";
                if(PaymentStatus==1 || RoleID == 1)
                    tds += "<td>" + PaymentStatusFormat(data.PaymentStatus) + "</td>";
                tds += "<td>" + UserOrderStatusFormat(data.OrderStatus) + "</td>";
                tds += "<td>" + NullFormat(GetText("stocks",data.IsFancy,data.Place,"Place")) + "</td>";  //所在地
                td_first += formatRMBPrice(data.ConfirmPrice);
                td_second += formatUSDPrice(data.ConfirmUSD);
                td_four+= formatUSDPrice(data.PriceUSD);
                td_third+= formatRMBPrice(data.PurchaseRMB);

                tr += "<tr class='data_tr' data-priceStatus="+data.ReceiptStatus+">" + tds + "</tr>";//将多列加到一行
                tr_div+="<tr class='stock_detail'><td colspan="+colspanVal+">"+
                    "<div class='detail_left' style='width:25%;'>"+
                    "<i><b>"+_("形状")+"：</b>" + GetText("stocks",1,data.Shape,"Shape") + "</i>" +
                    // "<i><b style='width:auto'>"+_("所在地")+"：</b>" + GetText("stocks",data.IsFancy,data.Place,"Place") + "</i>"+
                    "<i><b>"+_("切工")+"：</b>" + data.Cut + "</i>" +
                    "<i><b>"+_("抛光")+"：</b>" + data.Polish + "</i>" +
                    "<i><b>"+_("对称")+"：</b>" + data.Symmetry +"</i>" +
                    "<i><b>"+_("荧光")+"：</b>" + data.Fluorescence +"</i>" +
                    "<i><b>"+_("奶油")+"：</b>" + MilkyFormat(data.Milky) + "</i>"+
                    "<i onclick='showTotalWord(this)'><b class='custrom'>"+_("色调")+"：</b><span>" + HueFormat(data.Hue) + "</span></i>"+
                    "<i><b>"+_("心箭")+"：</b>" + HAFormat(data.HA) + "</i>"+
                    "<i onclick='showTotalWord(this)'><b class='custrom'>"+_("黑点")+"：</b><span>" + BlackDefectFormat(data.BlackDefect) + "</span></i>" +
                    "<i onclick='showTotalWord(this)'><b class='custrom'>"+_("瑕疵")+"：</b><span>" + OtherDefectFormat(data.OtherDefect) + "</span></i>" +
                    "<i><b>"+_("状态")+"：</b>" + NullFormat(StatusFormat(data.Status)) + "</i>"+
                    "<i style='color:red;font-weight:bold;'><b class='custrom' style='color:red;'>"+_("类型")+"：</b>" + CertTypeFormat(data) + "</i>" +
                    "<i data-value='"+data.InventoryID+"'  data-id='"+data.OrderID+"'><b class='' >"+_("图片")+"：</b>" + GetImgHd(data) + "</i>" +
                    "</div>" +
                    "<div class='detail_middle' style='width:33%;'>";
                if(RoleID == 1 || RoleID == 2 || RoleID == 3 || RoleID == 6) {
                    if(ConfirmPrice==1 || RoleID == 1){
                        tr_div+="<i onclick='ReviseAnOrder_Js(this)' value='" + data.OrderID + "' class='CurrentRMB'  style='color:red;font-weight:bold;'>"+
                            "<b class='custrom' style='color:red;'>"+_("卖")+"￥：</b>" + formatRMBPrice(data.ConfirmPrice) + "</i>";
                    }
                    if(ConfirmUSD==1 || RoleID == 1){
                        tr_div+="<i onclick='ReviseAnOrder_Js(this)' value='" + data.OrderID + "' class='CurrentUSD'  style='color:red;font-weight:bold;'>"+
                            "<b class='custrom' style='color:red;'>"+_("卖")+"$：</b>" + showReviseAnOrder(data) + "</i>" ;
                    }
                }
                if(SalesUserName==1 || RoleID == 1)
                    tr_div+="<i><b>"+_("业务")+"：</b>" + NullFormat(data.SalesUserName) + "</i>" ;
                if(PurchaseUserName==1 || RoleID == 1)
                    tr_div+= "<i><b>"+_("采购")+"：</b>" + NullFormat(data.PurchaseUserName) + "</i>";
                if(RoleID == 1 || RoleID == 2 || RoleID == 3 || RoleID == 6){
                    if(SalesExchangerate==1 || RoleID ==1){
                        tr_div+="<i><b>"+_("销汇")+"：</b>" + data.SalesExchangerate + "</i>";
                    }
                    if(Balance==1 || RoleID == 1)
                        tr_div+="<i class='ApplyFlow_Js CurrentRMB' data-id="+data.CustomerID+"><b>"+_("余")+"￥：</b>"+formatRMBPrice(data.Balance)+"</i>" ;
                    if(USDBalance==1 || RoleID == 1)
                        tr_div+="<i class='ApplyUSDFlow_Js CurrentUSD' data-id="+data.CustomerID+"><b>"+_("余")+"$：</b>"+formatUSDPrice(data.USDBalance)+"</i>";
                }
                if(RoleID == 1 || RoleID == 2 || RoleID == 4 || RoleID == 5 || RoleID == 6) {
                    if(data.Confirmdiscount - data.DiscountReturn <= 0 && data.OrderStatus != 5 && (DiscountReturn==1 || RoleID == 1)) {
                        tr_div+="<i><b class='custrom' style='width:auto'>"+_("原退点")+"：</b><span style='color:red;'>" + ConfirmdiscountFormat(data.DiscountReturn) + "</span></i>";
                    }else{
                        if(DiscountReturn==1 || RoleID == 1)
                            tr_div+="<i><b style='width:auto'>"+_("原退点")+"：</b>" + ConfirmdiscountFormat(data.DiscountReturn) + "</i>";
                    }
                    if(PurchaseRMB==1 || RoleID == 1)
                        tr_div+="<i class='CurrentRMB'><b class='custrom'>"+_("原")+"￥：</b>" + formatRMBPrice(data.PurchaseRMB) + "</i>";
                    if(PriceUSD==1 || RoleID == 1){
                        if(data.PriceUSD - data.ConfirmUSD >= 0) {
                            tr_div+="<i class='CurrentUSD'><b class='custrom'>"+_("原")+"$：</b><span style='color:red;'>" + formatUSDPrice(data.PriceUSD) + "</span></i>";
                        }else{
                            tr_div+="<i class='CurrentUSD'><b class='custrom'>"+_("原")+"$：</b>" + formatUSDPrice(data.PriceUSD) + "</i>";
                        }
                    }
                    if(PurchaseExchangerate==1 || RoleID == 1)
                        tr_div+= "<i><b>"+_("采汇")+"：</b>" + data.PurchaseExchangerate + "</i>";
                    if(ReceiptStatus==1 || RoleID == 1)
                        tr_div+= "<i><b class='custrom'>"+_("付款")+"：</b>" + ReceiptStatusFormat(data.ReceiptStatus) + "</i>";
                	}


                tr_div+="</div><div class='detail_right' style='width:42%;'>" +
                    "<i onclick='showTotalWord(this)'><b class='custrom'>"+_("尺寸")+"：</b><span>" + data.Measurement+ "</span></i>" ;

				if(data.orderMark == 1){
					tr_div+=   "<i onclick='showTotalWord(this)'><b class='custrom' style='width:auto'>"+_("证书号")+"：</b>" +
						"<span style='width:auto;'>" + CertNoFormat(data.CertNo) + "</span><img style='height:8px;padding-left:3px' src='/Images/mark.png' ></i>";
				}else{
					tr_div+=   "<i onclick='showTotalWord(this)'><b class='custrom' style='width:auto'>"+_("证书号")+"：</b><span style='width:auto;'>" + CertNoFormat(data.CertNo) + "</span></i>";
				}

			   		if(isHideSupplier == "1"){
					if(SupplierCode == 1 || RoleID == 1){
						if(Detail == 1 || RoleID == 1){
							tr_div += "<i><b class='custrom' style='width:auto'>" + _("供应商") + "：</b>" +
								"<span style='color:red' onclick='Contact_Js(this)' value=" + data.SupplierCode + ">" + data.SupplierCode + "</span></i>";
						} else {
							tr_div += "<i onclick='showTotalWord(this)'><b class='custrom' style='width:auto'>" + _("供应商") + "：</b><span>" + data.SupplierCode + "</span></i>";
						}
					}

				}

                tr_div+="<i onclick='showTotalWord(this)'><b class='custrom'>"+_("原货号")+"：</b><span>" + StringFormat(data.OriginSN) + "</span></i>" +
                    "<i><b class='custrom' style='width:auto'>"+_("下单时间")+"：</b><span>" + DateFormat(data.CreateTime) + "</span></i>" +
                    "<i><b style='width:auto'>"+_("到货时间")+"：</b>" + DateFormat(data.ArrivalTime) + "</i>" +
                    "<i><b class='custrom' style='width:auto'>"+_("出货时间")+"：</b><span>" + DateFormat(data.ShipTime) + "</span></i>";
                if(ShipNo==1 || RoleID == 1)
                    tr_div+="<i onclick='showTotalWord(this)'><b style='width:auto'>"+_("出货单号")+"：</b>" + NullFormat(data.ShipNo) + "</i>";
                tr_div+="<i><b>"+_("备注")+"</b></i>" +
                    "<i onclick='showTotalWord(this)'><b class='custrom'>"+_("客户")+"：</b><span>" + StringFormat(data.Remarks) + "</span></i>" +
                    "<i onclick='showTotalWord(this)'><b class='custrom'>"+_("业务")+"：</b><span>" + StringFormat(data.SalesRemarks) + "</span></i>" +
                    "<i onclick='showTotalWord(this)'><b class='custrom'>"+_("采购")+"：</b><span>" + StringFormat(data.PurchaseRemarks) + "</span></i>"+
                    "<i onclick='showTotalWord(this)'><b class='custrom'>"+_("物流")+"：</b><span>" + StringFormat(data.GoodsRemark) +"</span></i>"+
                    // "<i><b  class='custrom'>"+_("操作")+"：</b>" +
					// "<span onclick='ReviseAnOrder_Js(this)' value='" + data.OrderID + "' class='revise' style=''>"+_("售价")+"</span>" +
					// "<span class='purchase_modify revise' title='采购订单'  value='" + data.OrderID + "'>"+_("采购")+"</span></i>"+
                    "<i><b  class='custrom'>"+_("操作")+"：</b>" +showDiaModify(data)+"</i>"+

					// "<i><b onclick='ReviseAnOrder_Js(this)' value='" + data.OrderID + "'>"+_("操作")+"：<span style='border:solid 1px #ccc; text-align: center;'>"+_("售价")+"</span></b></i>"+
                    "</div></td></tr>";
                trs += tr + tr_div;//将单行加到多行
            }
            tableTbody.html(trs);//加入到id为customer的table的tbody中
            currentShow();  //币种设置
        }

    } else {
        //获取库存失败
        var tr = "";//单行
        var tds = "<td colspan='50' style='text-align:center;color:red'>" + _(_result["msginfo"]) + "</td>";// 多列合成一列并居中
        tr = "<tr>" + tds + "</tr>";//将多列加到一行
        tableTbody.html(tr);//加入到id为customer的table的tbody中
    }

}





//根据权限点击显示售价
 function showReviseAnOrder(result){
 	var data=result;
 	var OrderHtml="<span style='color:red' value='" + data.OrderID + "'>" + formatUSDPrice(data.ConfirmUSD) + "</span>";
 	var noHtml="<span>"+ formatUSDPrice(data.ConfirmUSD) + "</span>";
 	 //正常1-4
    if(data.OrderStatus < 5 && data.OrderStatus > 0){
        if(roleID == 1){
			return OrderHtml;
        }
        else if(data.PaymentStatus == 1 && data.ReceiptStatus == 1){
            //已收1 已付1
           return noHtml
        }
        else if(data.PaymentStatus == 1){
            //已收1
            return noHtml
        }else if(data.ReceiptStatus == 1){
            //已付1
            if(roleID == 3 || roleID == 6){
				return OrderHtml;
            }else{
                return noHtml
            }
        }else{
            if(roleID == 6){
				return OrderHtml;
            }else if(roleID == 3){
				return OrderHtml;
            }else if(roleID == 4 || roleID ==5){
               return noHtml
            }else{
                return noHtml
            }
        }
    }else{
        //异常5-7
        if(data.OrderStatus == 6 && data.Online != 1 && (roleID == 1 || roleID==5)){
        	return noHtml
           // tds += "<td class='check_toolbtn'><span class='modify' title='回裸钻库存' onclick='BackDia_Js(this)' value='" + _result[i].OrderID + "'>回库</span></td>";
        }else{
           return noHtml
        }
    }

 }


//转移ModifyPurchaseUserID 优惠ReviseOrders 备注RemarkOrder 确认到货ArrivalOrders 取消到货CancelArrivalOrders 预制单AddShip 打单PrintShip 出货EditShip 收款AddBill 付款ReceiptOrders 作废CancelOrders 自留StockOrders 退回ReturnOrders 兑率ExchangeOrders 删除DelOrders 运费ModFreight 现货款PayStock
function check_checkbutton(lib) {
 	var lis=lib;
    switch (lib) {
        // 1待采购 2待到货 3待出货 4已出货 5已作废 6 已自留 7已退回
        case 1: lib = '.ModifyPurchaseUserID,.ReviseOrders,.RemarkOrder,.CancelOrders,.PurchasePrice,.order_list_PurchaseExchangerate_btn,.StatusOrders'        //当订单状态为1时，RemarkOrder批量按钮亮 8-23
            break;
        case 2: lib = '.ReviseOrders,.ArrivalOrders,.RemarkOrder,.AddBill,.AddShip,.PurchasePrice,.order_list_PurchaseExchangerate_btn,.StatusOrders'  //.ExchangeOrders,
            break;
        case 3: lib = '.ReviseOrders,.AddShip,.PrintShip,.EditShip,.AddBill,.ReceiptOrders,.RemarkOrder,.EditShip,.ExchangeOrders,.CancelArrivalOrders,.StockOrders,.ReturnOrders,.PayStock,.ModFreight,.StatusOrders'
            break;
        case 4: lib = '.RemarkOrder,.PrintShip,.AddBill,.ReceiptOrders,.ExchangeOrders,.StockOrders,.ReturnOrders,.PayStock,.ModFreight,.StatusOrders' //运费11-11  只有已出货4才可以支付(收款 或 申请支付)
            break;
        case 5: lib = '.DelOrders,.RemarkOrder' //删除 9-29
            break;
        case 6: lib = '.DelOrders,.RemarkOrder'
            break;
        case 7: lib = '.DelOrders,.RemarkOrder,.AddBill'
            break;
        case 34: lib = '.ReceiptOrders,.AddBill,.ModFreight'   //待出货 已出货 两个订单状态时 付款 和 收款 、预制单、运费 亮
            break;
        default:
            break;
    }
    if ($("#stock_body .check_list_box span.selected").size() != 0) {
        $(lib).css("background-color", primary_color);
        $(lib).attr("disabled", false);
        $(".PlaceOrder,.PurchaseSupplierOrder").css("background-color", primary_color);
        $(".PlaceOrder,.PurchaseSupplierOrder").attr("disabled", false);

        //采购
	    PurchaseIsExit();
    } else {
        clearAll();
    }
    btnDelOrder();//回库删除按钮的高亮
	btnCancelOrders(lis);
}

function btnDelOrder(){
    var check_length = $("#stock_body .check_list_box span.selected");//选中
    var hasOnline=true;
    var isstu=false;//已作废
    var isstus=true;//其它状态
    for(var i=0;i<check_length.length;i++){
        var onlineVal=check_length.eq(i).attr("data-Online");
        var stu=check_length.eq(i).attr("data");
        if(onlineVal!=1){//已回库的才可以删除
            hasOnline=false;
        }
        if(stu!=5){
            isstus=false
        }
        if(stu==5){
            isstu=true;
        }
    }
    if(hasOnline==true && check_length.length>0){
        $(".DelOrders").css("background-color", primary_color);
        $(".DelOrders").attr("disabled", false);
    }else if(isstus&&isstu&& check_length.length>0){
        $(".DelOrders").css("background-color", primary_color);
        $(".DelOrders").attr("disabled", false);
    }else{
        $(".DelOrders").css("background-color", "#a1a1a1");
        $(".DelOrders").attr("disabled", true);
    }
}

//管理員在待到货下也可操作作废按钮
function btnCancelOrders(lib){
	if(RoleID==1 && lib == 2){
		$(".CancelOrders").css("background-color", primary_color);
		$(".CancelOrders").attr("disabled", false);
	}
}


//判断是否已经存在采购
function PurchaseIsExit(){
	var _Purchase = $("#stock_body .check_list_box span.selected");//采购
	var hasPurchase=false;//是否有采购
	var _PurchaseLen=0;
	if(roleID==1){
		if(_Purchase.length>0){
			$(".ModifyPurchaseUserID").css("background-color", primary_color);
	    	$(".ModifyPurchaseUserID").attr("disabled", false);
		}
	}else{
		//采购 已有采购的不能再选采购
		for(var i=0;i<_Purchase.length;i++){
			_PurchaseLen++;
			if(_Purchase.attr("data-Purchase")!="null" && _Purchase.attr("data-Purchase")!=undefined && _Purchase.attr("data-Purchase")!=""){
				hasPurchase=true;
			}
		}
		if(_PurchaseLen==_Purchase.length){//循环完之后再判断
			if(hasPurchase==false){
	        	$(".ModifyPurchaseUserID").css("background-color", primary_color);
	            $(".ModifyPurchaseUserID").attr("disabled", false);
	        }else{
	        	$(".ModifyPurchaseUserID").attr("disabled", true);
		    	$(".ModifyPurchaseUserID").css("background-color", "#a1a1a1");
	        }
		}
	}

	var _type=$("#stock_body .check_list_box span.selected").attr("data");
	if(_type==1 || _type==2 || _type==3 || _type==4){
		$(".ReviseOrders,.RemarkOrder,.PlaceOrder,.PurchasePrice,.PurchaseExchangerate,.StatusOrders").css("background-color", primary_color);
		$(".ReviseOrders,.RemarkOrder,.PlaceOrder,.PurchasePrice,.PurchaseExchangerate,.StatusOrders").attr("disabled", false);
	}
}
function clearAll() {
    $(".search_btn_b,.search_btn_p").attr("disabled", true);
    $(".search_btn_b,.search_btn_p").css("background-color", "#a1a1a1");
	//采购
	PurchaseIsExit();
}
//获取汇率
 function getRate(){
 	  $.ajax({
        url: "/Team/GetRate",//提交地址
        type: "POST",//提交方式
        //data: "",
        data: "{'SysSettingID':'1'}", //1裸钻
        contentType: "application/json; charset=utf-8",
        success: function (result) {
            var _result = JSON.parse(result);
            rate=_result["data"].Rate;
            globalDiscountReturn=_result["data"].GlobalDiscountReturn;
        }
    });
 }

 //客户列表
 function CustomersLoad(){
     var requestCustomer={};

     //业务员3 采购员4 物流员 5
     if(roleID == 3 || roleID == 4 || roleID == 5)
     {
         requestCustomer.SalesUserID = UserID;
     }

     requestCustomer.SysStatus = 1;//正常的客户 9-29

     $.ajax({
         url: "/Team/GetCustomerList",//提交地址
         type: "POST",//提交方式
         async: false, //异步 9-27
         data: JSON.stringify(requestCustomer),
         contentType: "application/json; charset=utf-8",
         success: function (result) {
             var _result = JSON.parse(result);

             if(_result.msgcode == false){

             } else {
             	var availableTags = [];
             	 for (var i = 0; i < _result.length; i++) {
             	 	availableTags.push(_result[i].NickName);
             	 }
				$("#_customerCs").autocomplete({
				  source: availableTags
				});
             }
         }
     });

 }

 //供应商列表
 function SuppliersLoad() {
     $.ajax({
         url: "/Team/GetSupplierList",//提交地址
         type: "POST",//提交方式
         data: "",
         contentType: "application/json; charset=utf-8",
         success: function (result) {
             var _result = JSON.parse(result);
             if (_result.msgcode == false) {

             } else {
				var availableTags = [];
             	 for (var i = 0; i < _result.length; i++) {
             	 	availableTags.push(_result[i].SupplierCode);
             	 }
				$("#_supplierCs").autocomplete({
				  source: availableTags
				});
             }

         }
     });
 }

 //业务列表
 function SalesLoad(){

     var requestSales={};

     //业务员3
     if(roleID == 3)
     {
         requestSales.UserID = UserID;
     }

     requestSales.SysStatus = 1;//正常的团队 10-28

     $.ajax({
         url: "/Team/GetSaleList",//提交地址
         type: "POST",//提交方式
         data: JSON.stringify(requestSales),
         contentType: "application/json; charset=utf-8",
         success: function (result) {
             var _result = JSON.parse(result);

             if(_result.msgcode == false){

                 var options_sales = "";
                 options_sales += '<option value="">' + _(_result.msginfo) + '</option>';
                 $("#_salesUserID").html("");
                 $("#_salesUserID").html(options_sales);

             }else{

                 var options_sales = "";
                 options_sales += '<option value="">'+_("业务")+'</option>';
                 for (var i = 0; i < _result.length; i++) {
                     options_sales += '<option value="' + _result[i].UserID + '"  >' + _result[i].RealName + '</option>';
                 }
                 $("#_salesUserID").html("");
                 $("#_salesUserID").html(options_sales);
             }
         }
     });
 }

 //采购列表
 function PurchasesLoad(){

     var requestPurchases={};

     //采购4
     if(roleID == 4)
     {
         requestPurchases.UserID = UserID;
     }

     requestPurchases.SysStatus = 1;//正常的团队 10-28

     $.ajax({
         url: "/Team/GetPurchaseList",//提交地址
         type: "POST",//提交方式
         data: JSON.stringify(requestPurchases),
         contentType: "application/json; charset=utf-8",
         success: function (result) {
             var _result = JSON.parse(result);

             if(_result.msgcode == false){
                 var options_purchases = "";
                 options_purchases += '<option value=""  >' + _(_result.msginfo)+ '</option>';
                 $("#_purchaseUserIDs").html("");
                 $("#_purchaseUserIDs").html(options_purchases);

             }else{

                 var options_purchases = "";
                 options_purchases += '<option value="">'+_("采购")+'</option>';
                 for (var i = 0; i < _result.length; i++) {
                     options_purchases += '<option value="' + _result[i].UserID + '"  >' + _result[i].RealName + '</option>';
                 }
                 $("#_purchaseUserIDs").html("");
                 $("#_purchaseUserIDs").html(options_purchases);
             }

         }
     });
 }


// 获取图片和视频
function GetImgHd(data){
	var str = "";
	if(data.HasImage==1){
        str +='<img alt="图片" src="/images/imageIcon.png" class="ImageIcon" />';
    }
	if(data.HasVideo==1){
		str+='<img alt="视频" src="/images/videoIcon.png" class="VideoIcon" />'
	}
	return str;
}

function ShowColumn(columnName){
	var roles='';
	if(APP){
		var userAgent=navigator.userAgent;
		var indes=userAgent.lastIndexOf('/');
		var banben=userAgent.substring(indes+1,indes+6);
		var  arr=banben.split('.');
		var url=window.location.href;
		if((url.indexOf("eegia")!=-1 && Number(arr[0])>1)||(url.indexOf("eegia")!=-1 && Number(arr[1])>=9) || (url.indexOf("zb315")!=-1 && Number(arr[0])>1)||(url.indexOf("zb315")!=-1 && Number(arr[1])>=9)){
			roles= YiYi_APP.getUserRoles().split(',');
		}else if( url.indexOf("zuanfeifan")!=-1 || url.indexOf("zb315")!=-1 || url.indexOf("musegia")!=-1 ||url.indexOf('ywgia')!=-1 || url.indexOf('58gia')!=-1 ){
			roles= YiYi_APP.getUserRoles().split(',');
		}else{
			if($.cookie("UserRoles")){
				roles =$.cookie("UserRoles").split(',')
			}
		}
	}else{
		roles = UserRoles.split(',');
	}

	if (roles != null)
	{
		for (var i = 0; i < roles.length; i++) {
			if (roles[i] == "."+columnName) {
				return true;
			}
		}
		return false;
	}
}

function showDiaModify(data){
	var str="";
    if (data.OrderStatus < 5 && data.OrderStatus > 0) {
        if(RoleID ==1&&data.OrderStatus == 4){
            str+=    "<span class='purchase_modify revise' style='border:solid 1px #ccc; text-align: center;' title='采购订单'  value='" + data.OrderID + "'>"+_("采购")+"</span>"+
                "<span class='modify revise' title='修改售价' style='border:solid 1px #ccc; text-align: center;'  value='" + data.OrderID + "' onclick='ReviseAnOrder_Js(this)'>"+_("售价")+"</span>";

        }
        else if(order_price_btn == 1 || RoleID==1){

              str+=  "<span class='modify revise' title='修改售价' style='border:solid 1px #ccc; text-align: center;'  value='" + data.OrderID + "' onclick='ReviseAnOrder_Js(this)'>"+_("售价")+"</span>";

            if(order_procurement_btn == 1 || RoleID==1){
                str +="<span class='purchase_modify revise' title='采购订单' style='border:solid 1px #ccc; text-align: center;' value='" + data.OrderID + "'>"+_("采购")+"</span>";
            }

        }
        else if(menu_order_procurement_btn == 1 || RoleID==1){

             str+=   "<span class='purchase_modify revise' title='采购订单' style='border:solid 1px #ccc; text-align: center;' value='" + data.OrderID + "'>"+_("采购")+"</span></td>";
            if(order_price_btn == 1){
               str +="<span class='modify revise' title='修改售价' style='border:solid 1px #ccc; text-align: center;' value='" + data.OrderID + "' onclick='ReviseAnOrder_Js(this)'>"+_("售价")+"</span>";
            }

        }

        else if (data.PaymentStatus == 1 && data.ReceiptStatus == 1) {
            //已收1 已付1
            str += "<span class='check_toolbtn_order'></span>";
        }
        else if (data.OrderStatus == 4 && RoleID == 3) {
            //已出货限制
            str += "<span class='check_toolbtn_order'></span>";
        }
        else if (data.PaymentStatus == 1) {
            //已收1
            if (RoleID == 4 || RoleID == 5 || RoleID == 6) {
                str += "<td class='check_toolbtn_order' style='width:15%'>"+
                    "<span class='purchase_modify revise' title='采购订单' style='border:solid 1px #ccc; text-align: center;'  value='" + data.OrderID + "'>"+_("采购")+"</span></td>";
            } else {
               str += "<span class='check_toolbtn_order'></span>";
            }
        } else if (data.ReceiptStatus == 1) {
            //已付1
            if (RoleID == 3 || RoleID == 6) {

                 str+=   "<span class='modify revise' title='修改售价' style='border:solid 1px #ccc; text-align: center;' value='" + data.OrderID + "' onclick='ReviseAnOrder_Js(this)'>"+_("售价")+"</span></td>";
            } else {
               str += "<span class='check_toolbtn_order'></span>";
            }
        } else {
            if (RoleID == 6||RoleID == 7) {

                str+=    "<span class='purchase_modify' title='采购订单' style='border:solid 1px #ccc; text-align: center;' value='" + data.OrderID + "'>"+_("采购")+"</span>"+
                    "<span class='modify revise' title='修改售价' onclick='ReviseAnOrder_Js(this)' value='" + data.OrderID + "'>"+_("售价")+"</span></td>";
            } else if (RoleID == 3) {

                str+=    "<span class='purchase_modify' title='采购订单' style='border:solid 1px #ccc; text-align: center;'  value='" + data.OrderID + "'>"+_("采购")+"</span>"+
                    "<span class='modify revise' title='修改售价'  value='" + data.OrderID + "' onclick='ReviseAnOrder_Js(this)'>"+_("售价")+"</span>";
            } else if (RoleID == 4 || RoleID == 5) {

                str+=    "<span class='purchase_modify' title='采购订单' style='border:solid 1px #ccc; text-align: center;'  value='" + data.OrderID + "'>"+_("采购")+"</span></td>";
            } else {
               str += "<span class='check_toolbtn_order'></span>";
            }
        }
    } else {
        // 异常
        if (data.OrderStatus == 6 && data.Online != 1 && (RoleID == 1 || RoleID == 5)) {
            if(order_price_btn == 1||order_procurement_btn == 1||(RoleID ==1&&data.OrderStatus == 4)){
                str += "<span class='check_toolbtn_order'></span>";//<span title='回裸钻库存' onclick='BackDia_Js(this)' value='" + data.OrderID + "'>"+_("回库")+"</span>
            }

        } else {
            if(order_price_btn == 1||order_procurement_btn == 1||(RoleID ==1&&data.OrderStatus == 4)){
                str += "<span class='check_toolbtn_order'></span>";
            }
        }
    }

    return str;

}

